import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  // 路由表,标记当前用户所拥有的路由
  routes: constantRoutes // 默认静态路由
}
const mutations = {
  setRoutes(state, otherRoutes) {
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}
const actions = {
  // 筛选路由权限
  filterRoute(context, menu) {
    // console.log(menu)
    const otherRoutes = asyncRoutes.filter(item => {
      return menu.includes(item.children[0].name)
    })
    context.commit('setRoutes', otherRoutes)
    return otherRoutes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
